using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using System.IO;
using System.Collections;
using System.Diagnostics;
namespace first
{
   [TestFixture]
   public class TestLargest
    {

        [Test]
        public void LargestOf3() {
            int[] arr = new int[] { 7, 6, 9 };
            Assert.AreEqual(9, Cmp.Largest(arr));
        }

       [Test]
       public void TestDup()
       {
           int[] arr = new int[] { 7, 9, 6, 9 };
           Assert.AreEqual(9, Cmp.Largest(arr));
       }

       [Test]
       public void TestNegative()
       {
           int[] arr = new int[] { -7, -9, -1 };
           Assert.AreEqual(-1, Cmp.Largest(arr));
       }

       [Test]
       public void TestOne()
       {
           int[] arr = new int[] {3};
           Assert.AreEqual(3, Cmp.Largest(arr));
       }

       [Test, ExpectedException(typeof(ArgumentException))]
       public void TestEmpty()
       {
           Cmp.Largest(new int[]{});
       }
       [Test]
       public void TestLargestDateFile() {
           StreamReader sr = new StreamReader("../../data/dataFile.txt");
           string line;
           while ((line=sr.ReadLine()) != null) {
               if (line.StartsWith("#"))
               {
                   continue;
               }
               string[] tokens = line.Split(null);
               int expected = Int32.Parse(tokens[0]);
               Trace.WriteLine(expected.ToString());
               ArrayList arl = new ArrayList();
               for (int i = 1; i < tokens.Length; i++)
               {
                   int val = Int32.Parse(tokens[i]);
                   Trace.WriteLine(val.ToString());
                   arl.Add(val);
               }

               int[] testArr = (int[])arl.ToArray(typeof(int));
               Assert.AreEqual(expected, Cmp.Largest(testArr));
          }
       }

    }
}
